from django.utils.deprecation import MiddlewareMixin
from django.http import JsonResponse

class LoginMiddleware(MiddlewareMixin):
    def process_view(self, request, view_func, view_args, view_kwargs):
        if request.path == '/api/login/' or request.path == '/api/token/' or request.path == '/staff/active/':
            return None
        if not request.user.is_authenticated:
            return JsonResponse({'code': 401, 'msg': '请先登录'}, status=401)
